Function Reference

FileCopy

Copies one or more files.

FileCopy ( "source", "dest" [, flag] )

 

Parameters

source The source path of the file(s) to copy. Wildcards are supported.
dest The destination path of the copied file(s).
flag [optional] this flag determines whether to overwrite files if they already exist.
Can be a combination of the following:
 0 = (default) do not overwrite existing files
 1 = overwrite existing files
 8 = Create destination directory structure if it doesn't exist (See Remarks).

 

Return Value

Success: Returns 1.
Failure: Returns 0.

 

Remarks

The destination directory must already exist, except using with flag value '8'.
For instance the combined flag '9' (1 + 8) overwrites the target file and pre-checks for the destination directory structure and if it doesn't exist creates it automatically.

See FileFindFirstFile for a discussion of wildcards.

 

Related

FileMove, FileDelete, DirCopy

 

Example


FileCopy("C:\*.au3", "D:\mydir\*.*")

; Method to copy a folder (with its contents)
DirCreate("C:\new")
FileCopy("C:\old\*.*", "C:\new\")

; Do not overwrite but create directory structure if it doesn't exist
FileCopy("C:\Temp\*.txt", "C:\Temp\TxtFiles", 8)
; FALSE - 'TxtFiles' works here like a single file name (like DOS "copy file1 + file2 +...")

FileCopy("C:\Temp\*.txt", "C:\Temp\TxtFiles\", 8)
; RIGHT - 'TxtFiles' is now the target directory and the file names are given by the source names

FileCopy("C:\Temp\*.txt", "C:\Temp\TxtFiles\", 9) ; Flag = 1 + 8 (overwrite + create target directory structure)
; Copy the txt-files from source to target and overwrite target files with same name